﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Inference
{
	public partial class ucHighlighterSettings : UserControl
	{
		public Highlighter BoundedHighlighter
		{
			get;
			set;
		}

		public LinkTypes BoundedLink
		{
			get;
			set;
		}

		public Settings BoundedSettings
		{
			get;
			set;
		}

        public frmPreferences parentForm 
        { 
            get; 
            set; 
        }

        public bool Checked
        {
            get 
            {
                return cbxOnOff.Checked;
            }
            set
            {
                cbxOnOff.Checked = value;
            }
        }

        public Color ChosenColor
        {
            get
            {
                return lblCurrentColor.BackColor;
            }
            set
            {
                lblCurrentColor.BackColor = value;
            }
        }

		public ucHighlighterSettings()
		{
			InitializeComponent();
		}

        public ucHighlighterSettings(Highlighter BoundedHighLighter, frmPreferences parentForm)
		{
			InitializeComponent();
            this.parentForm = parentForm;
			this.BoundedHighlighter = BoundedHighLighter;
			cbxOnOff.Checked = BoundedHighLighter.Enabled;
			lblCurrentColor.BackColor = BoundedHighLighter.HighlightColor;
			lblDescription.Text = BoundedHighLighter.Description;
		}

		public ucHighlighterSettings(LinkTypes linkType, Settings settings, frmPreferences parentForm)
		{
			InitializeComponent();
			BoundedSettings = settings;
			BoundedLink = linkType;
            this.parentForm = parentForm;
			switch (linkType)
			{
				case LinkTypes.is_a:
					cbxOnOff.Checked = BoundedSettings.LinksSettings.ShowISA;
					lblCurrentColor.BackColor = BoundedSettings.LinksSettings.ColorISA;
					lblDescription.Text = "Отображение связей IS_A";
					break;
				case LinkTypes.next:
					cbxOnOff.Checked = BoundedSettings.LinksSettings.ShowNEXT;
					lblCurrentColor.BackColor = BoundedSettings.LinksSettings.ColorNEXT;
					lblDescription.Text = "Отображение связей NEXT";
					break;
				case LinkTypes.sub:
					cbxOnOff.Checked = BoundedSettings.LinksSettings.ShowSUB;
					lblCurrentColor.BackColor = BoundedSettings.LinksSettings.ColorSUB;
					lblDescription.Text = "Отображение связей SUB";
					break;
				default:
					break;
			}
		}

		private void btnChooseColor_Click(object sender, EventArgs e)
		{
			if (BoundedHighlighter != null)
			{
				ColorDialog cdlg = new ColorDialog();
				cdlg.Color = BoundedHighlighter.HighlightColor;
				if(cdlg.ShowDialog() == DialogResult.OK)
				{
					lblCurrentColor.BackColor = cdlg.Color;
				}
			}else
				if (BoundedLink != null)
				{
					ColorDialog cdlg = new ColorDialog();
					switch (BoundedLink)
					{
						case LinkTypes.is_a:
							cdlg.Color = BoundedSettings.LinksSettings.ColorISA;
							break;
						case LinkTypes.next:
							cdlg.Color = BoundedSettings.LinksSettings.ColorNEXT;
							break;
						case LinkTypes.sub:
							cdlg.Color = BoundedSettings.LinksSettings.ColorSUB;
							break;
						default:
							break;
					}
					if (cdlg.ShowDialog() == DialogResult.OK)
					{
						lblCurrentColor.BackColor = cdlg.Color;
					}
				}
		}

		public void UpdateHighlighter()
		{
			if (BoundedHighlighter != null)
			{
				BoundedHighlighter.Enabled = cbxOnOff.Checked;
				BoundedHighlighter.HighlightColor = lblCurrentColor.BackColor;
			}else
				if (BoundedLink != null)
				{
					switch (BoundedLink)
					{
						case LinkTypes.is_a:
							BoundedSettings.LinksSettings.ColorISA = lblCurrentColor.BackColor;
							BoundedSettings.LinksSettings.ShowISA = cbxOnOff.Checked;
							break;
						case LinkTypes.next:
							BoundedSettings.LinksSettings.ColorNEXT = lblCurrentColor.BackColor;
							BoundedSettings.LinksSettings.ShowNEXT = cbxOnOff.Checked;
							break;
						case LinkTypes.sub:
							BoundedSettings.LinksSettings.ColorSUB = lblCurrentColor.BackColor;
							BoundedSettings.LinksSettings.ShowSUB = cbxOnOff.Checked;
							break;
						default:
							break;
					}
				}
		}

        private void cbxOnOff_CheckedChanged(object sender, EventArgs e)
        {
            parentForm.CheckCheckBoxes();
        }
	}
}
